package com.eco.fanliapp.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.eco.fanliapp.entity.AppUserOrder;
import com.eco.fanliapp.entity.JdUserOrder;
import com.eco.fanliapp.entity.PddUserOrder;
import com.eco.fanliapp.vo.AppUserFansTeamVo;
import com.eco.fanliapp.vo.DoubleElevenUserVo;
import com.eco.fanliapp.vo.DoubleTwelveUserVo;
import com.eco.fanliapp.vo.SyChannelUserVO;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户和订单中间 数据层
 * 
 * @author xiaoxx
 * @date 2019-04-24
 */
public interface AppUserOrderMapper extends BaseMapper<AppUserOrder>
{
	/**
     * 查询用户和订单中间信息
     * 
     * @param tableId 用户和订单中间ID
     * @return 用户和订单中间信息
     */
	AppUserOrder selectAppUserOrderById(Integer tableId);
	
	/**
     * 查询用户和订单中间列表
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 用户和订单中间集合
     */
	List<AppUserOrder> selectAppUserOrderList(AppUserOrder appUserOrder);
	
	/**
     * 新增用户和订单中间
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 结果
     */
	int insertAppUserOrder(AppUserOrder appUserOrder);
	
	/**
     * 修改用户和订单中间
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 结果
     */
	int updateAppUserOrder(AppUserOrder appUserOrder);
	
	/**
     * 删除用户和订单中间
     * 
     * @param tableId 用户和订单中间ID
     * @return 结果
     */
	int deleteAppUserOrderById(Integer tableId);
	
	/**
     * 批量删除用户和订单中间
     * 
     * @param tableIds 需要删除的数据ID
     * @return 结果
     */
	int deleteAppUserOrderByIds(String[] tableIds);

	AppUserOrder selectAppUserOrderBybalanceCount(Long userId);

	/**
	 * 查询该用户绑定订单数
	 * @param userId
	 * @return
	 */
	int countBingOrderSum(Long userId);

	/**
	 * 
	 * @param tradeId
	 * @return
	 */
	AppUserOrder selectAppUserOrderByTradeId(Long tradeId);

	/**
	 * 
	 * @param tradeId
	 * @return
	 */
	List<AppUserOrder> selectAppUserOrderListByTradeId(Long tradeId);

	/**
	 * 
	 * @param userId
	 * @param i
	 * @return
	 */
	double findBalanceListByUserId(@Param("userId") Long userId, @Param("i") int i);

	/**
	 *
	 * @param list
	 * @param i
	 * @return
	 */
	HashMap<String, Object> findFansSuperBalanceSumByUserId(List<Long> list, int i);

	/**
	 *
	 * @param userId
	 * @param i
	 * @return
	 */
	String findFansLevelBalanceSumByUserId(Long userId, int i);

	/**
	 *
	 * @return
	 */
	List<AppUserOrder> selectLargeAmountYesList(@Param("starTime") Long starTime,@Param("endTime") Long endTime);

    /**
     * 订单号找
     * @param tradeId
     * @return
     */
    AppUserOrder selectAppUserOrderByTradeIdNew(Long tradeId);
	/**
	 *
	 * @param userId
	 * @return
	 */
	List<AppUserOrder> selectAppUserOrderByUserId(Long userId);

	/**
	 *
	 * @param userId
	 * @return
	 */
	List<AppUserOrder> selectAppUserOrderByUserIdAndTkStatus3(Long userId);

	/**
	 *
	 * @param userId
	 * @param i
	 * @return
	 */
	HashMap<String, Object> findBalanceByUserIdSum(@Param("userId") Long userId, @Param("i") int i);

	/**
	 * 查询订单数量（根据userId）
	 * @param userIds
	 * @return
	 */
	int buyNumByAllId(List<Long> userIds);

	/**
	 * 查询用户购买免单商品订单数量（根据userId）
	 *
	 * @param taobaoUserId
	 * @return
	 */
	int buyFreeNumByAllId(@Param("taobaoUserId") Long taobaoUserId);
	/**
	 * 查询用户订单分佣金额
	 * @param userId
	 * @param tradeId
	 * @return
	 */
	AppUserOrder findUserIdOrderId(@Param("userId") Long userId, @Param("tradeId") Long tradeId);


	/**
	 * 取我的收益-入账中订单-包含自己订单，直接粉丝订单，间接粉丝订单，分享赚订单     tkStatus = 12
	 *
	 * @param userId
	 * @param invoCode
	 * @return
	 */
	List<AppUserOrder> getMeBookedOrderDetail(@Param("userId") Long userId, @Param("invoCode") String invoCode, @Param("start") Integer start, @Param("back") Integer back);

	List<AppUserOrder> selectUserOrder(Long userId);

    List<AppUserFansTeamVo> findFansTeamList(@Param("userId") Long userId, @Param("start") Integer start, @Param("back") Integer back);

	Double statisticsCommission(@Param("flag") Integer flag, @Param("companyId") Integer companyId, @Param("startTime")long startTime, @Param("endTime")long endTime);

	Integer yesterdayOrderRepeat(@Param("companyId") Integer companyId, @Param("flag") Integer flag, @Param("startTime")long startTime, @Param("endTime")long endTime);

	double singleZeroPurchaseCost(@Param("companyId") Integer companyId, @Param("flag") Integer flag, @Param("startTime")long startTime, @Param("endTime")long endTime);

	double yesterdayZeroPurchaseCost();

	int firstShareRatio(@Param("companyId") Integer companyId, @Param("flag") Integer flag, @Param("startTime")long startTime, @Param("endTime")long endTime);

	int yesterdayFirstShareRatio();

	Integer yesterdayAddingUsers(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

	String singleInitialCost(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

	Integer yesterdaySubsidyFreeAmount(@Param("companyId") Integer companyId);

	Double freeAllianceCommissionYesterday(@Param("companyId") Integer companyId,@Param("type") Integer type,
													@Param("startDate")Long startDate,@Param("endDate") Long endDate);

    List<DoubleElevenUserVo> selectDoubleElevenUser(@Param("type") Integer type, @Param("starTime") Long starTime, @Param("endTime") Long endTime);

    BigDecimal selectDoubleElevenUserCommission(@Param("userId") Long userId);

	Integer totalOrderUserRegistration(@Param("companyId") Integer companyId);

	Integer yesterdayOrderQuantity(@Param("companyId") Integer companyId);

	Integer selectTotalOrder(@Param("companyId") Integer companyId, @Param("flag") Integer flag, @Param("startTime")long startTime, @Param("endTime")long endTime);

	int updatePressllOrder(@Param("userId") Long userId, @Param("orderId") String orderId, @Param("newCommission") BigDecimal newCommission);

	AppUserOrder selectOrderByOrderIdAndUserId(@Param("userId") Long userId, @Param("orderId") Long orderId);

	List<DoubleElevenUserVo> selectDoubleElevenUser2(@Param("type") Integer type);

	Double timeLimitedCommission(@Param("companyId") Integer companyId, @Param("flag") Integer flag,@Param("types")Integer types);

	String todayHotCommission(@Param("companyId") Integer companyId, @Param("flag") Integer flag);

	String voucherCommission(@Param("companyId") Integer companyId, @Param("flag")Integer flag);

    Integer getOrderCountNumber(Long userId);

	/**
	 * 双十二中奖名单
	 * @return
	 */
    List<DoubleTwelveUserVo> doubleTwelveDownload(@Param("minPrice")Double minPrice,@Param("maxPrice")Double maxPrice , @Param("starTime")Long starTime ,@Param("endTime") Long endTime);

	/**
	 * 假名单150个
	 */
	List<DoubleTwelveUserVo> doubleTwelveDownloadFalse();


	AppUserOrder selectOrderTypeByUser(@Param("userId") Long userId,@Param("itemId")Long itemId);

	Double singleFixedReturnYesterday(@Param("companyId")Integer companyId, @Param("flag")Integer flag);

	SyChannelUserVO selectOrderMessage(@Param("channelId")Long channelId, @Param("searchDate")String searchDate);

	Integer selectOrderUser(@Param("channelId")Long channelId, @Param("flag")Integer flag,@Param("freeFlag")Integer freeFlag);

	Integer withdrawPermissionCount(@Param("userId")Long userId);

	Integer withdrawPermissionCountTwo(@Param("userId")Long userId);

	Integer recommendedOrderNum(@Param("companyId")Integer companyId, @Param("flag")Integer flag, @Param("types")Integer types);

	Integer OrderRepeat(@Param("companyId")Integer companyId);

	Double channelPubSharereFee(@Param("companyId")Integer companyId, @Param("groupId")Integer groupId, @Param("flag")Integer flag);

	Double pubCommisssionPubSharePreFee(@Param("companyId")Integer companyId, @Param("type")Integer type,
										@Param("startDate")Long startDate,@Param("endDate") Long endDate);

	Integer payOrderTotalNum(@Param("companyId")Integer companyId, @Param("type")Integer type,@Param("startDate")Long startDate,@Param("endDate") Long endDate);

	Double payOrderTotalMoney(@Param("companyId")Integer companyId, @Param("type")Integer type,@Param("startDate")Long startDate,@Param("endDate") Long endDate);

	int totalGoodFreesNum(@Param("companyId")Integer companyId, @Param("orderType")Integer orderType, @Param("type")Integer type,@Param("startDate")Long startDate,@Param("endDate") Long endDate);

	Double totalGoodFreesMoney(@Param("companyId")Integer companyId, @Param("orderType")Integer orderType, @Param("type")Integer type,@Param("startDate")Long startDate,@Param("endDate") Long endDate);

	Integer sqjdOrderNum();

	Map<String,Double> sqjdCommision();

	Map<String,Double> sqjdTypeCommision(@Param("companyId")Integer companyId,@Param("orderType")Integer orderType,@Param("goodFrees")Integer goodFrees);

	Integer sqjdAllOrderNum();

	Map<String,Object> freeCommssion();

	Double zgsAllCommission();

	Map<String,Object> selectChannelNums(@Param("type")Integer type);

    JdUserOrder selectJdOrderBybalanceCount(@Param("userId")Long userId);

	PddUserOrder selectPddOrderBybalanceCount(@Param("userId")Long userId);

	JdUserOrder selectUserJdOrder(@Param("userId")Long userId);

	PddUserOrder selectUserPddOrder(@Param("userId")Long userId);
}